package rebot

import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type RobotDevice struct{
	gorm.Model
	Name string
	DeviceLocalID string
	LevelLocalID string
	CompanyID string
	Phone string 
	Email string 
	DeviceTypeID string
	Identity string
	Longitude string
	Latitude string
	PosistionID string
	ClientIP string
	ClientPort string
	FromCompany string
	FromBrand string
	VideoID string
	VideoType string
	Salt string
	LoginTime time.Time
	IsLogout bool
	DeviceInfo string
	Function string
	ActionLimit string
 }

 func (table *RobotDevice) TableName() string {

	return "robot_device_basic"
}

func GetRobotDeviceList() []*RobotDevice { 
	data := make([]*RobotDevice,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindRobotDeviceByName(name string) RobotDevice {
	user := RobotDevice{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindRobotDeviceByID(id uint) RobotDevice {
	user := RobotDevice{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func FindRobotDeviceByTypeIDAndCompanyID(id string,CompanyID string) []*RobotDevice {
	user := make([]*RobotDevice,100)
	utils.DB.Where("level_local_id = ? and company_id = ?",id,CompanyID).Find(&user)
	return user
}

func CreateRobotDevice(user RobotDevice) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func DeleteRobotDevice(user RobotDevice) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateRobotDevice(user RobotDevice) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(RobotDevice{Name: user.Name,DeviceTypeID: user.DeviceTypeID,Longitude: user.Longitude, Latitude: user.Latitude,VideoID: user.VideoID ,VideoType: user.VideoType ,FromCompany: user.FromCompany,FromBrand: user.FromBrand, Function: user.Function, ActionLimit: user.ActionLimit, DeviceInfo: user.DeviceInfo,})
}